
var ztaqxsChart;
var returnZtaqxsData = [];

var ztaqxsObj = new Vue({
	el: '#ztaqxsTab',
	data: {
		year: '',
		isAll: false,
		zsList:{
			sgzs: true,
			xsg: false,
			ybjyssg: false,
			swsz: false,
			cc: false,
			zjjjss: false
		},
		tbList: {
			sgzstb: true,
			xsgtb: false,
			ybjyssgtb: false,
			swsztb: false,
			cctb: false,
			zjjjsstb: false
		},
		hbList: {
			sgzshb: true,
			xsghb: false,
			ybjyssghb: false,
			swszhb: false,
			cchb: false,
			zjjjsshb: false
		}
	},
	created: function(){


	},
	watch:{
		"zsList.sgzs":function(val, oldVal){	//事故总数
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"zsList.xsg":function(val, oldVal){	//小事故
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"zsList.ybjyssg":function(val, oldVal){	//一般及以上事故
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"zsList.swsz":function(val, oldVal){	//死亡/失踪
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"zsList.cc":function(val, oldVal){	//沉船
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"zsList.zjjjss":function(val, oldVal){	//直接经济损失
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"zsList.sgzs":function(val, oldVal){	//事故总数
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"zsList.xsg":function(val, oldVal){	//小事故
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"zsList.ybjyssg":function(val, oldVal){	//一般及以上事故
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"zsList.swsz":function(val, oldVal){	//死亡/失踪
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"zsList.cc":function(val, oldVal){	//沉船
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"zsList.zjjjss":function(val, oldVal){	//直接经济损失
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"tbList.sgzstb":function(val, oldVal){	//事故总数同比
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"tbList.xsgtb":function(val, oldVal){	//小事故同比
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"tbList.ybjyssgtb":function(val, oldVal){	//一般及以上事故同比
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"tbList.swsztb":function(val, oldVal){	//死亡/失踪同比
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"tbList.cctb":function(val, oldVal){	//沉船同比
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		}
		/*,
		"tbList.zjjjsstb":function(val, oldVal){	//直接经济损失同比
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"hbList.sgzshb":function(val, oldVal){	//事故总数环比
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"hbList.xsghb":function(val, oldVal){	//小事故环比
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"hbList.ybjyssghb":function(val, oldVal){	//一般及以上事故环比
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"hbList.swszhb":function(val, oldVal){	//死亡/失踪环比
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"hbList.cchb":function(val, oldVal){	//沉船环比
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		},
		"hbList.zjjjsshb":function(val, oldVal){	//直接经济损失环比
    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		}*/
	},
	methods:{
		checkAll: function(){
			this.zsList.sgzs = this.isAll;
			this.zsList.xsg　= this.isAll;
			this.zsList.ybjyssg　= this.isAll;
			this.zsList.swsz = this.isAll;
			this.zsList.cc　= this.isAll;
			this.zsList.zjjjss　= this.isAll;

			this.tbList.sgzstb = this.isAll;
			this.tbList.xsgtb　= this.isAll;
			this.tbList.ybjyssgtb　= this.isAll;
			this.tbList.swsztb = this.isAll;
			this.tbList.cctb　= this.isAll;
			this.tbList.zjjjsstb　= this.isAll;

			/*
			this.hbList.sgzshb = this.isAll;
			this.hbList.xsghb　= this.isAll;
			this.hbList.ybjyssghb　= this.isAll;
			this.hbList.swszhb = this.isAll;
			this.hbList.cchb　= this.isAll;
			this.hbList.zjjjsshb　= this.isAll;
			*/

    		ztaqxsChart.setOption(subStrOptionZtaqxs(returnZtaqxsData),true)
		}
	}
})

function searchOrTimeaqxs(){
	if($('#timeaqxs').val()==""){
		ztaqxsObj.year =new Date().getFullYear();
	}
	else{
		ztaqxsObj.year =$('#timeaqxs').val();}
	$.ajax({ 
		type: "POST",
		url: "/tszt/findsjfb.jspx", 
		data: {channelIds: 386, year: ztaqxsObj.year, orderBy: 36},
		success: function(data){
			if(data.code == 200){
				if(data.body.length == 0){
					ztaqxsObj.year = new Date().getFullYear() - 1;
					bindZtaqxsData();
				}
				returnZtaqxsData = data.body;
			}

			bindZtaqxs(returnZtaqxsData);//运输旅客总数初始化
      	}
	});
}
function bindZtaqxsData(){
	if(returnZtaqxsData.length == 0){

		$.ajax({ 
			type: "POST",
			url: "/tszt/findsjfb.jspx", 
			data: {channelIds: 368, year: ztaqxsObj.year, orderBy: 36},
			success: function(data){
				if(data.code == 200){
					if(data.body.length == 0){
						ztaqxsObj.year = new Date().getFullYear() - 1;
						bindZtaqxsData();
					}
					returnZtaqxsData = data.body;
				}
	
				bindZtaqxs(returnZtaqxsData);//运输旅客总数初始化
	      	}
		});
	}
}

function subStrLegendZtaqxs(){
	var legend = [];

	if(ztaqxsObj.zsList.sgzs)
		legend.push('事故总数');
    if(ztaqxsObj.zsList.xsg)
		legend.push('小事故');
    if(ztaqxsObj.zsList.ybjyssg)
		legend.push('一般及以上事故');
	if(ztaqxsObj.zsList.swsz)
		legend.push('死亡失踪人数');
    if(ztaqxsObj.zsList.cc)
		legend.push('沉船');
    if(ztaqxsObj.zsList.zjjjss)
		legend.push('直接经济损失');
	return legend;
}

function subStrXAxisZtaqxs(returnZtaqxsData){
	var xAxis = [];
	if(returnZtaqxsData.length<12){
		xAxis=['1月份','2月份','3月份','4月份','5月份','6月份','7月份','8月份','9月份','10月份','11月份','12月份'];
	}
	else{
	returnZtaqxsData.forEach(function(month){ 
		xAxis.push(month.attr_month + '月份');
	}); 
	}
	return xAxis;
}


function subStrSeriesZtaqxs(returnZtaqxsData){
	var series = [];
	
	var sgzsData = [];
	var sgzsDataTb = [];
	var sgzsDataHb = [];

	var xsgData = [];
	var xsgDataTb = [];
	var xsgDataHb = [];

	var ybjyssgData = [];
	var ybjyssgDataTb = [];
	var ybjyssgDataHb = [];

	var swszData = [];
	var swszDataTb = [];
	var swszDataHb = [];

	var ccData = [];
	var ccDataTb = [];
	var ccDataHb = [];

	var zjjjssData = [];
	var zjjjssDataTb = [];
	var zjjjssDataHb = [];


	returnZtaqxsData.forEach(function(val){ 
		//事故总数
		sgzsData.push(val.attr_sgzs); //总数
		sgzsDataTb.push(val.attr_sgzstb);	//同比
		//sgzsDataHb.push(val.attr_sgzshb);//环比
		//小事故
		xsgData.push(val.attr_xsg); //总数
		xsgDataTb.push(val.attr_xsgtb);	//同比
		//xsgDataHb.push(val.attr_xsghb);//环比
		//一般及以上事故
		ybjyssgData.push(val.attr_ybjyssg); //总数
		ybjyssgDataTb.push(val.attr_ybjyssgtb);	//同比
		//ybjyssgDataHb.push(val.attr_ybjyssghb);//环比
		//死亡/失踪
		swszData.push(val.attr_swsz); //总数
		swszDataTb.push(val.attr_swsztb);	//同比
		//swszDataHb.push(val.attr_swszhb);//环比
		//沉船
		ccData.push(val.attr_cc); //总数
		ccDataTb.push(val.attr_cctb);	//同比
		//ccDataHb.push(val.attr_cchb);//环比
		//直接经济损失
		zjjjssData.push(val.attr_zjjjss); //总数
		zjjjssDataTb.push(val.attr_zjjjsstb);	//同比
		//zjjjssDataHb.push(val.attr_zjjjsshb);//环比
	}); 
	

	if(ztaqxsObj.zsList.sgzs){	//事故总数
	    var d = 
		{
            name: '事故总数',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#5bc0de",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: sgzsData
        };
	    series.push(d);
	}

	if(ztaqxsObj.tbList.sgzstb){	//事故总数同比
		var d = 
      	{
             name: '事故总数同比',
             type: 'line',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
					 color: "#FF3300",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: sgzsDataTb
        };

	    series.push(d);
	}


	if(ztaqxsObj.hbList.sgzshb){	//事故总数环比
		var d = 
      	{
             name: '事故总数环比',
             type: 'scatter',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#336633",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: sgzsDataHb
        };

	    series.push(d);
	}


	if(ztaqxsObj.zsList.xsg){	//小事故
	    var d = 
		{
            name: '小事故',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#5cb85c",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: xsgData
        };
	    series.push(d);
	}

	if(ztaqxsObj.tbList.xsgtb){	//小事故同比
		var d = 
      	{
             name: '小事故同比',
             type: 'line',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#5cb85c",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: xsgDataTb
        };

	    series.push(d);
	}


	if(ztaqxsObj.hbList.xsghb){	//小事故环比
		var d = 
      	{
             name: '小事故环比',
             type: 'scatter',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#5cb85c",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: xsgDataHb
        };

	    series.push(d);
	}

	if(ztaqxsObj.zsList.ybjyssg){	//一般及以上事故
	    var d = 
		{
            name: '一般及以上事故',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#0078c1",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: ybjyssgData
        };
	    series.push(d);
	}

	if(ztaqxsObj.tbList.ybjyssgtb){	//一般及以上事故同比
		var d = 
      	{
             name: '一般及以上事故同比',
             type: 'line',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#0078c1",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: ybjyssgDataTb
        };

	    series.push(d);
	}


	if(ztaqxsObj.hbList.ybjyssghb){	//一般及以上事故环比
		var d = 
      	{
             name: '一般及以上事故环比',
             type: 'scatter',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#0078c1",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: ybjyssgDataHb
        };

	    series.push(d);
	}

	if(ztaqxsObj.zsList.swsz){	//死亡/失踪人数
	    var d = 
		{
            name: '死亡失踪人数',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#f0ad4e",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: swszData
        };
	    series.push(d);
	}

	if(ztaqxsObj.tbList.swsztb){	//死亡/失踪人数同比
		var d = 
      	{
             name: '死亡失踪人数同比',
             type: 'line',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#f0ad4e",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: swszDataTb
        };

	    series.push(d);
	}


	if(ztaqxsObj.hbList.swszhb){	//死亡/失踪人数环比
		var d = 
      	{
             name: '死亡失踪人数环比',
             type: 'scatter',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#f0ad4e",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: swszDataHb
        };
		

	    series.push(d);
	}

	if(ztaqxsObj.zsList.cc){	//沉船
	    var d = 
		{
            name: '沉船',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#996600",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: ccData
        };
	    series.push(d);
	}

	if(ztaqxsObj.tbList.cctb){	//沉船同比
		var d = 
      	{
             name: '沉船同比',
             type: 'line',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#996600",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: ccDataTb
        };

	    series.push(d);
	}

	if(ztaqxsObj.hbList.cchb){	//沉船环比
		var d = 
      	{
             name: '沉船环比',
             type: 'scatter',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#996600",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: ccDataHb
        };
		

	    series.push(d);
	}

	if(ztaqxsObj.zsList.zjjjss){	//直接经济损失
	    var d = 
		{
            name: '直接经济损失',
            type: 'bar',
            itemStyle: {
                normal: {
					color: "#FF3300",
                    label: {
                    	show: true,
                        position: 'top',
                        formatter: '{c}'
                    }
                }
            },
            data: zjjjssData
        };
	    series.push(d);
	}

	if(ztaqxsObj.tbList.zjjjsstb){	//直接经济损失同比
		var d = 
      	{
             name: '直接经济损失同比',
             type: 'line',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#FF3300",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: zjjjssDataTb
        };

	    series.push(d);
	}


	if(ztaqxsObj.hbList.zjjjsshb){	//直接经济损失环比
		var d = 
      	{
             name: '直接经济损失环比',
             type: 'scatter',
             yAxisIndex: 1,
             itemStyle: {
                 normal: {
						color: "#FF3300",
                     label: {
                         show: true,
                         position: 'top',
                         formatter: '{c}%'
                     }
                 }
             },
             data: zjjjssDataHb
        };
		

	    series.push(d);
	}

	return series;
}

function subStrOptionZtaqxs(){

	var legendData = subStrLegendZtaqxs();
	var xAxisData = subStrXAxisZtaqxs(returnZtaqxsData);
	var seriesData = subStrSeriesZtaqxs(returnZtaqxsData);
//alert(ztaqxsObj.zsList.xsg);
    var option = {
    		toolbox: {
  			　　show: true,
  			   right: 20,     			  
  			　　feature: {
  			　　　　saveAsImage: {
  			　　　　show:true,
  			　　　　excludeComponents :['toolbox'],
  			　　　　pixelRatio: 2,
  			  itemStyle: {
  	                color: '#254065'
  	            }
  			　　　　}
  			　　}
  			},
    		title: {
    			text: ztaqxsObj.year + '年'
    		},	
    		
    		 tooltip: {
              	trigger: 'axis',
              	 axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                      type: 'line'        //指示器类型。
                  },
                  formatter: function (params) {//提示框自定义
                      return formatterTip(params);
                  },
                 
     		 },

            legend: {
                data: legendData,
                textStyle: {
                    color: '#A7A7A7',
                },
            },
          
            xAxis: {
                data: xAxisData
            },

            yAxis: [
            	{
                    type: 'value',
                    name: '总数'
                },
                {
                    type: 'value',
                    axisLabel: {
                        show: true,
                        interval: 'auto',
                        formatter: '{value}%'
                    },
                    name: '百分比%'
                }
            ],
        
           series: seriesData
		};
    
    
    return option;
}


//运输旅客总数图表初始化
function bindZtaqxs(returnZtaqxsData){

	ztaqxsChart = echarts.init(document.getElementById('chartZtaqxs'));

    var option = subStrOptionZtaqxs(returnZtaqxsData);
	
    // 使用刚指定的配置项和数据显示图表。
    ztaqxsChart.setOption(option);
}